## Makefile , By Duan Haixin

CC=gcc

CFLAGS= -c  -g
LIBFLAGS=   -lpthread 
INSTALL_DIR=/usr/local/tunnet

EXECUTE= tunnet
CONTROL= command

target:  $(EXECUTE) $(CONTROL)

common.o:common.c  common.h
	$(CC) $(CFLAGS) common.c  -o common.o 

config.o:config.c  config.h tunnet.c tunnet.h
	$(CC) $(CFLAGS) config.c   

tunnet.o:tunnet.c   tunnet.h
	$(CC) $(CFLAGS) tunnet.c   

socks.o: socks.c socks.h global.h
	$(CC) $(CFLAGS) socks.c 

controller_server.o: controller_server.c tunnet.h global.h
	$(CC) $(CFLAGS) controller_server.c 
	
controller_client.o: controller_client.c tunnet.h global.h common.h
	$(CC) $(CFLAGS) controller_client.c 


main.o: main.c tunnet.h  global.h 
	$(CC) $(CFLAGS) main.c 

command.o: command.c tunnet.h  global.h
	$(CC) $(CFLAGS) command.c 

$(EXECUTE):main.o tunnet.o config.o common.o socks.o controller_server.o controller_client.o 
	   $(CC) -g $(LIBFLAGS)   -o tunnet main.o common.o config.o tunnet.o socks.o controller_server.o controller_client.o 
$(CONTROL):command.o command.o config.o tunnet.o socks.o  
	   $(CC) $(LIBFLAGS) -o command  common.o config.o  command.o tunnet.o socks.o

clean:
	rm -f *.o; rm  $(EXECUTE) $(CONTROL)
install:
	mkdir -p $(INSTALL_DIR); cp -f $(CONTROL) $(INSTALL_DIR); cp -f $(EXECUTE) $(INSTALL_DIR); cp -f *.conf $(INSTALL_DIR);\
	cp -f tunnet-script.pl $(INSTALL_DIR)
